
//计算文件大小
function lzGetFileSize(appByts) {
	var mb = 1024 * 1024;
	if (appByts > mb) {
		var bb = appByts / (1024 * 1024);
		bb = Math.floor(bb * 100) / 100;
		return bb + "MB";
	}
	var bk = appByts / 1024;
	bk = bk.toFixed(1);
	return bk + "KB";
}
//计算文件格式传入后缀
function lzGetFileType(suffix) {
	if (suffix == 'jpg' || suffix == 'jpeg' || suffix == "png" || suffix == "bpm" || suffix == "BPM" || suffix == 'PNG' ||
		suffix ==
		'gif' || suffix == 'GIF') {
		return require('../../static/image/filemanag/image.png')
	} else if (suffix == 'doc' || suffix == 'docx' || suffix == 'DOC' || suffix == 'DOCX') {
		return require('../../static/image/filemanag/doc.png')
	} else if (suffix == 'xlsx' || suffix == 'xls' || suffix == 'XLSX' || suffix == 'XLS') {
		return require('../../static/image/filemanag/xlsx.png')
	} else if (suffix == 'txt' || suffix == 'TXT') {
		return require('../../static/image/filemanag/TXT.png')
	} else if (suffix == 'zip' || suffix == 'rar') {
		return require('../../static/image/filemanag/zip.png')
	} else if (suffix == 'pdf' || suffix == 'PDF') {
		return require('../../static/image/filemanag/pdf.png')
	} else if (suffix == 'mp4' || suffix == 'wmv' || suffix == 'avi' || suffix == 'MP4' || suffix == 'WMV' || suffix ==
		'AVI') {
		return require('../../static/image/filemanag/shipin.png')
	} else if (suffix == 'mp3' || suffix == 'm4a' || suffix == 'wma' || suffix == 'MP3' || suffix == 'M4A' || suffix ==
		'WMA') {
		return require('../../static/image/filemanag/yinpin.png')
	} else {
		return require('../../static/image/filemanag/weizhi.png')
	}
}
//判断打开的文件类型
function lzGetTypeSuffix(suffix) {
	let result = ''
	const imglist = ['png', 'jpg', 'jpeg', 'bmp', 'gif', 'PNG', 'JPG', 'JPEG', 'BMP', 'GIF'];
	const wordList = ['doc', 'xls', 'ppt', 'pdf', 'docx', 'xlsx', 'pptx', 'DOC', 'XLS', 'PPT', 'PDF', 'DOCX', 'XLSX',
		'PPTX', 'txt'
	];
	const videoList = ['mp4', 'wmv', 'avi', 'MP4', 'WMV', 'AVI'];
	const audioList = ['mp3', 'm4a', 'wma', 'MP3', 'M4A', 'WMA'];
	result = imglist.find(item => item === suffix);
	if (result) {
		return 'image';
	}
	result = wordList.find(item => item === suffix);
	if (result) {
		return 'word';
	}
	result = videoList.find(item => item === suffix);
	if (result) {
		return 'video';
	}
	result = audioList.find(item => item === suffix);
	if (result) {
		return 'audio';
	}

}

module.exports = {
	lzGetFileSize,
	lzGetFileType,
	lzGetTypeSuffix,
}
